package com.example.home7;

import android.app.Notification;
import android.app.PendingIntent;
import android.content.ComponentName;
import android.content.Intent;
import android.content.ServiceConnection;
import android.os.Build;
import android.os.Bundle;
import android.os.IBinder;
import android.view.View;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.annotation.RequiresApi;
import androidx.fragment.app.Fragment;

import com.example.home7.server.MusicLuaLuaLua2;

public class bindServer extends Fragment {
    public bindServer() {
        super(R.layout.bind);
    }


    public class abcWA implements ServiceConnection {
        private MusicLuaLuaLua2.MyBinder binWA = null;
        @Override
        public void onServiceConnected(ComponentName name, IBinder service) {
            binWA = (MusicLuaLuaLua2.MyBinder) service;
        }

        @Override
        public void onServiceDisconnected(ComponentName name) {

        }
    }
    private  abcWA AiJIaoSHAJIuJIaoSHAWA;//爱叫什么就叫什么
    @RequiresApi(api = Build.VERSION_CODES.O)
    @Override
    public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
        super.onViewCreated(view, savedInstanceState);

        Intent notificationIntent = new Intent(getActivity(), MusicLuaLuaLua2.class);

        getActivity().startService(new Intent(getActivity(), MusicLuaLuaLua2.class));

        if(AiJIaoSHAJIuJIaoSHAWA == null){
            AiJIaoSHAJIuJIaoSHAWA = new abcWA();
            getActivity().bindService(new Intent(getActivity(),MusicLuaLuaLua2.class),
                    AiJIaoSHAJIuJIaoSHAWA, 0);
        }

        getView().findViewById(R.id.button10).setOnClickListener(
                new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        if(AiJIaoSHAJIuJIaoSHAWA.binWA == null)
                            return;
                        AiJIaoSHAJIuJIaoSHAWA.binWA.play();
                    }
                }
        );
        getView().findViewById(R.id.button11).setOnClickListener(
                new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        AiJIaoSHAJIuJIaoSHAWA.binWA.next();
                    }
                }
        );
        getView().findViewById(R.id.button12).setOnClickListener(
                new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        AiJIaoSHAJIuJIaoSHAWA.binWA.pause();
                    }
                }
        );
    }
}
